package com.zoweunion.mechanic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.entity.TSSsVehicleTypeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.dao.TSSsVehicleBrandDao;
import com.zoweunion.mechanic.entity.TSSsVehicleBrandEntity;
import com.zoweunion.mechanic.service.TSSsVehicleBrandService;


@Service("tSSsVehicleBrandService")
public class TSSsVehicleBrandServiceImpl extends ServiceImpl<TSSsVehicleBrandDao, TSSsVehicleBrandEntity> implements TSSsVehicleBrandService {

    @Autowired
    private TSSsVehicleBrandDao tSSsVehicleBrandDao;


    @Override
    public PageInfo queryPage(Map<String, Object> map) {
        Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
        Integer currentPage = Integer.valueOf(map.get("currentPage").toString());
        PageHelper.startPage(currentPage, pageSize);
        List<TSSsVehicleBrandEntity> mapList = tSSsVehicleBrandDao.queryPage(map);
        PageInfo<TSSsVehicleBrandEntity> mapPageInfo = new PageInfo<>(mapList);
        return mapPageInfo;
    }

    @Override
    public List<TSSsVehicleBrandEntity> tSSsVehicleBrandListFor(Map<String, Object> params) {
        LambdaQueryWrapper<TSSsVehicleBrandEntity> lambdaQuery =
                Wrappers.<TSSsVehicleBrandEntity>lambdaQuery();
        lambdaQuery.like(true, TSSsVehicleBrandEntity::getBrandName,
                        params.get("brandName").toString());
        if (!params.get("typeId").toString().isEmpty()){
            lambdaQuery.and(i->i.eq(true, TSSsVehicleBrandEntity::getTypeId,
                    params.get("typeId").toString()));
        }
        return tSSsVehicleBrandDao.selectList(lambdaQuery);
    }

}